<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ include file="/common/taglib.jsp" %>

<!DOCTYPE html>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%@ include file="/common/css.jsp" %>
<%@ include file="/common/javascript.jsp" %>

<script type="text/javascript">
<!--
jQuery(function(){

	// query list
	jQuery( "#query" ).button().click(function(){
		jQuery("#action").val('list');
		jQuery("form").submit();
	});

	// new 
	jQuery( "#new" ).button().click(function(){
		jQuery("#action").val('new');
		jQuery("form").submit();
	});
	
	// remove
	jQuery( "#remove" ).button().click(function(){
		var keys = jQuery("table tbody tr td input:checkbox:checked");
		if(keys){
			if(keys.length > 0){
				jQuery("#action").val('mutilRemove');
				jQuery("form").submit();
			}else{
				jQuery('#msgDIV').html("<ui:message code="delete.null" isError="1"/>");
			}
		}
	});;

	// list table	
	jQuery("#listTable").listTable();
});


function selectAllCK(dom){
	var checked = jQuery(dom).attr('checked');
	jQuery('td input:checkbox').each(function(){
		if(checked){
			jQuery(this).attr('checked',true);
		}else{
			jQuery(this).attr('checked',false);
		}
	});
}
//-->
</script>

</head>

<body>
<div id="msgDIV" style="margin:0px; padding:0px;"><ui:message code="${code}" isError="${isError}"/></div>
	<fieldset>
		<form:form id="queryForm" method="post" action="/admin/menu.do">
		<form:hidden path="action"/>
		<form:hidden path="pageNo"/>
		<form:hidden path="pageSize"/>
		<form:hidden path="total"/>
		<form:hidden path="pageNumber"/>
		
		<form:hidden path="modelId"/>
		
			<table id="queryTable" class="ui-widget ui-widget-content"  style="width:100%">
					<thead>
						<tr class="ui-widget-header">
							<td>
								<input type="button" id="query" value="<spring:message code="query"/>"/>
								<input type="button" id="new" value="<spring:message code="new"/>"/>
								<input type="button" id="remove" value="<spring:message code="remove"/>"/>
							</td>
						</tr>
					</thead>
				<tbody>
					<tr>
						<td><spring:message code="menu.menuName"/></td>
					</tr>
					<tr>
						<td><form:input path="menuName"/></td>
					</tr>
				</tbody>
			</table>
			
	<table id="listTable" class="ui-widget ui-widget-content" style="width:100%">
		<thead>
			<tr class="ui-widget-header">
				<th><spring:message code="sequence"/></th>
				<th>
					<label for="selectAll">
						<input type="checkbox" id="selectAll" name="selectAll" onclick="selectAllCK(this)"/>
						<spring:message code="selectAll"/>
					</label>
				</th>
				<th><spring:message code="model.modelName"/></th>
				<th><spring:message code="menu.menuName"/></th>
				<th><spring:message code="menu.menuURL"/></th>
				<th><spring:message code="row.enable"/></th>
				<th><spring:message code="operate"/></th>
			</tr>
		</thead>
		<tbody>
		<c:forEach var="obj" items="${list}" varStatus="status">
			<tr>
				<td>${status.count+((command.pageNo-1)*command.pageSize)}</td>
				<td><input type="checkbox" id="CK${status.count}" name="keys" value="${obj.menuId}"/></td>
				<td>${obj.modelName}</td>
				<td>${obj.menuName}</td>
				<td>${obj.menuURL     }</td>
				<td>${obj.rowEnable      }</td>
				<td>
					<a href="<c:url value="/admin/menu.do?action=edit&menuId=${obj.menuId}&modelId=${obj.modelId}"/>"><span><spring:message code="edit"/></span></a>
					<a href="<c:url value="/admin/menu.do?action=remove&menuId=${obj.menuId}&modelId=${obj.modelId}"/>"><span><spring:message code="remove"/></span></a>
				</td>
			</tr>
		</c:forEach>
		</tbody>
		
		<tfoot>
		<tr>
			<td colspan="9" align="right">
				<a href="#" onclick="paging(1)"><span><spring:message code="paging.first"/></span></a>
				<a href="#" onclick="paging(2)"><span><spring:message code="paging.prev"/></span></a>
				<a href="#" onclick="paging(3)"><span><spring:message code="paging.next"/></span></a>
				<a href="#" onclick="paging(4)"><span><spring:message code="paging.last"/></span></a>
				<spring:message code="paging.jump.to"/>
				<select id="pagingJumpId" onchange="pagingJump(this.value)">
					<c:forEach var="obj" begin="1" end="${command.pageNumber }">
						<option value="${obj}">${obj}</option>
					</c:forEach>
				</select>
				<spring:message code="paging.jump.to.number"/>
			</td>
		</tr>
		<script type="text/javascript"><!--		
			function paging(t){
				var pn = parseInt(jQuery('#pageNo').val());
				var pageNumber = parseInt(jQuery('#pageNumber').val());
				if(t == 1){
					jQuery('#pageNo').val(1);
				}else if(t == 2){
					if(pn > 1){
						jQuery('#pageNo').val(pn-1);
					} else { 
						var msg = "<ui:message code="paging.isFirst" isError="1"/>";
						jQuery('#msgDIV').html(msg); 
						return; }
				}else if(t == 3){
					if(pn < pageNumber){
						jQuery('#pageNo').val(pn+1);
					} else {
						var msg = "<ui:message code="paging.isLast" isError="1"/>";
						jQuery('#msgDIV').html(msg); 
						return; 
					}
				}else if(t == 4){
					var pagingFloat = parseFloat(jQuery('#total').val()/jQuery('#pageSize').val());
					var pagingInt   = parseInt(jQuery('#total').val()/jQuery('#pageSize').val());
					if(pagingFloat > pagingInt)
						jQuery('#pageNo').val(pagingInt+1);
					else
						jQuery('#pageNo').val(pagingInt);
				}
				jQuery("form").submit();
			}			
			function pagingJump(t){
				jQuery('#pageNo').val(t);
				jQuery("form").submit();
			}
			jQuery('#pagingJumpId').val(jQuery('#pageNo').val());
		//-->
		</script>
		</tfoot>
	</table>
	
		</form:form>
	</fieldset>
        
</body>

</html>
